{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "53048371-7c09-4a8c-8a2a-18f2c850c46e",
   "metadata": {},
   "source": [
    "- 解包\n",
    "\n",
    "assert 是断言语句, 不返回值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "bf73ce11-0161-495f-bb85-9f750b8a890c",
   "metadata": {},
   "outputs": [],
   "source": [
    "a, *b, c = [1, 2, 3, 4, 5]\n",
    "assert b == [2, 3, 4]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08131858-e9ed-4c08-9f81-14159d6e2cfd",
   "metadata": {},
   "source": [
    "- 函数参数是解包参数, 即元祖. 调用时注意对应的参数形式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "7d125dcf-155f-4030-8bf3-f1711d056f5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def self_add(*nums):\n",
    "    return [x + 1 for x in nums]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b52bcb82-f4cf-44dd-8350-afaf96b77f2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([3, 4, 5], [2, 3, 4])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [1, 2, 3]\n",
    "v1 = self_add(2, 3, 4)\n",
    "v2 = self_add(*nums)\n",
    "v1, v2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c894937-0699-45b3-b941-d21aa7e89c11",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (myenv)",
   "language": "python",
   "name": "myenv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
